﻿using Domain.Entity;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EfCore.Configers
{
    public class RoleJurisdictionConfigers : IEntityTypeConfiguration<RoleJurisdiction>
    {
        public void Configure(EntityTypeBuilder<RoleJurisdiction> builder)
        {
            // 指定表名
            builder.ToTable(nameof(RoleJurisdiction));

            // 配置主键
            builder.HasKey(e => e.RolesJID);

            // 配置外键关系
            builder.HasOne(e => e.Role)
                   .WithMany()
                   .HasForeignKey(e => e.RolesID); // 外键关联角色表

            builder.HasOne(e => e.Jurisdiction)
                   .WithMany()
                   .HasForeignKey(e => e.JuriID); // 外键关联权限表
        }
    }
}
